#include<bits/stdc++.h>
#define int long long
#define fff(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
int n;
const int N=2e5+5;
int a[N],ans=-1;
void dg(int dep,int redlas,int bluelas,int sum){
    if(dep>n){
        ans=max(ans,sum);
    }
    else{
        int zl=0;
        if(redlas==a[dep])zl=a[dep];
        dg(dep+1,a[dep],bluelas,sum+zl);
        zl=0;
        if(bluelas==a[dep])zl=a[dep];
        dg(dep+1,redlas,a[dep],sum+zl);
    }
}
void solve(){
    ans=-1;
    cin>>n;
    fff(i,1,n)cin>>a[i];
    if(n<=28){dg(1,-1,-1,0);cout<<ans<<'\n';}
    else cout<<0<<'\n';
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--)solve();
    return 0;
}